package fr.mywiki.model.ejbAdapter.entity;

import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.EntityBean;

import fr.mywiki.business.structure.StructureLite;

/**
 * @ejb.bean name="Structure"
 *		local-jndi-name="ejb/MyWiki/Structure"
 *		view-type="local"
 *		cmp-version="2.x"
 *		primkey-field="id"
 *		schema="Structure"
 *
 * @ejb.persistence table-name="structure"
 * 
 * @ejb.finder view-type="local"
 *		signature="java.util.Collection findAll()"
 *		unchecked="true"
 *		query="SELECT OBJECT(e) FROM Structure e"
 *		result-type-mapping="Local"
 * 
 * @author tlombard
 */
public abstract class StructureBean extends EntityAdapter implements EntityBean {
	/**
	 * @ejb.create-method
	 */
	public Long ejbCreate(Long id) throws CreateException {
		setId(id);
		return id;
	}
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id"
	 */
	public abstract Long getId();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id"
	 */
	public abstract void setId(Long id);
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="name"
	 */
	public abstract String getName();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="name"
	 */
	public abstract void setName(String name);
	
	/**
	 * @ejb.interface-method view-type = "local"
	 * @ejb.relation 
	 *    name="parent-children-structure"
	 *    role-name="ParentToChildren"
	 *    target-role-name = "ChildToParent"
	 */
	public abstract Collection getChildren();

	/**
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setChildren(
			Collection structures);

	/**
	 * @ejb.interface-method view-type = "local"
	 * @ejb.relation 
	 * 		name="parent-children-structure"
	 * 		role-name="ChildToParent"
	 * 		target-role-name = "ParentToChildren"
	 * @jboss.relation
	 * 		related-pk-field="id"
	 * 		fk-column="parent_id"
	 */
	public abstract StructureLocal getParent();

	/**
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setParent(StructureLocal a);
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="struct_model"
	 */
	public abstract String getStructureModel();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="struct_model"
	 */
	public abstract void setStructureModel(String structureModel);
	
	/**
	 * @ejb.interface-method view-type="local"
	 *
	 * @ejb.relation name="Account-to-Structure"
	 *		role-name="Structure-has-many-accounts"
	 *		target-role-name="Account-has-one-structure"
	 */
	 public abstract Collection getAccounts();

	 /**
	  * @ejb.interface-method
	  */
	public abstract void setAccounts(Collection c);
	
	/**
	 * @ejb.interface-method view-type="local"
	 */
	public StructureLite getStructureLite() {
		StructureLite structure = new StructureLite();

		structure.setId(getId());
		structure.setName(getName());
		structure.setStructureModel(getStructureModel());
		
		return structure;
	}
}
